package com.example.qjia.util.retrofit;


import com.example.qjia.basic.MyApplication;
import com.example.qjia.data.romotedata.AbsenceSlip;
import com.example.qjia.data.romotedata.ResponseData;
import com.example.qjia.data.romotedata.Result;
import com.example.qjia.data.romotedata.Student;
import com.example.qjia.data.romotedata.person;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ying_xiang on 2016/8/20.
 */
public class RetrofitNet {
    private QjiaService service;

    public RetrofitNet() {
        this.service =new OkHttpUtils().getService();;
    }

    public  <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
        observable.subscribeOn(Schedulers.io())
                .subscribeOn(Schedulers.newThread())//子线程访问网络
                .observeOn(AndroidSchedulers.mainThread())//回调到主线程
                .subscribe(observer);
    }
    public void login(String studentId,String password,Observer<ResponseData<Student>> observer) {    //调用retrofitApi接口函数
        setSubscribe(service.login(studentId,password),observer);
    }
    public void register(String studentName,String pwd,String studentId,String studentTel,String master,String masterClass,String acadamy,String mail,Observer<Result> observer) {    //调用retrofitApi接口函数
        setSubscribe(service.registerStudent(studentName,studentId,pwd,mail,studentTel,acadamy,master,masterClass),observer);
    }

    public void addAbsenceSlip(Map<String,String>AbsenceSlipParams,Observer<ResponseData>observer){
        setSubscribe(service.addAbsenceSlip(AbsenceSlipParams),observer);//老师的id还没有定义，六个参数
    }
    public void getStudentById(Observer<ResponseData<Student>>observer){//通过sid获取学生信息
        setSubscribe(service.getStudent(MyApplication.getStudentId()+""),observer);
    }
    public void updateStudentInfo( Map<String,String >params,Observer<ResponseData> observer){
        setSubscribe(service.UpdateStudentInfo(params),observer);          //更改学生的信息
    }
    public void getAbsenseSlipByPage(Map<String,String>absenseSlipMap, //获取学生请假列表的信息
    Observer<ResponseData<List<AbsenceSlip>>>observer){
        setSubscribe(service.getAbsenseByPage(absenseSlipMap),observer);
    }

    public void getAbsenseSlip(String aid,Observer<ResponseData<AbsenceSlip>>observer){
        setSubscribe(service.getAbsenseSlipById(aid),observer);
    }


}
